<template>
	<view class="login">
		<input type="text"  class="inputStyle" placeholder="酒名" :value="name" @input="inputChange"  data-key="name"/>
		<input type="number"  class="inputStyle" placeholder="价格" :value="price" @input="inputChange"  data-key="price"/>
		<input type="text"  class="inputStyle" placeholder="数量" :value="volume" @input="inputChange" data-key="volume" />
		<input type="text"  class="inputStyle" placeholder="地址" :value="area" @input="inputChange" data-key="area" />
		<!-- <input type="text" value="" class="inputStyle" placeholder="容积" />
		<input type="text" value="" class="inputStyle" placeholder="日期" />
		<input type="text" value="" class="inputStyle" placeholder="年份" />	 -->
		
		
	
		<button type="" class="buttonStyle" @click="adddata">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid:uni.getStorageSync('userInfo').uid,
				area:'',
				name:null,
				price:null,
				volume:null,
				cstatus:true
				
			}
		},
		onLoad() {
			
		},
		methods: {
			inputChange(e){
				const key = e.currentTarget.dataset.key;
				this[key] = e.detail.value;
			},
			adddata(){
				
				
				if(!this.cstatus){
					
					return;
				}
				
				
				if(this.name==null||this.price==null||this.volume==null){
					uni.showModal({
						title: "不能有空值",
						content: "不能有空值！",
						showCancel: false,
						confirmText: "确定"
					})
					return;
				}
				
				uni.showLoading({
				     title: '提交中...'
				 });
				this.cstatus=false;
				
				const sendData = {
					"uid": this.uid,
					"name":  this.name,
					//"name":  encodeURI(this.name),
					"price": this.price,//这里先传银行编号，后续确定了在修改
					"volume": this.volume,
					"area":this.area
					
				};
				
					uni.request({
						url: this.webUrl+'/addsell', //仅为示例，并非真实接口地址。
						data: sendData,
						dataType: 'json',
						method: 'POST',
						header: {
							'content-type': 'application/json' // 微信默认就是
						},
						success: res => {
							console.log(res.data );
							if (res.statusCode !== 404) {
								
								
								uni.showModal({
									title: "操作成功",
									content: "操作成功！",
									showCancel: false,
									confirmText: "确定",
									   success: function (res) {
									        if (res.confirm) {
									            console.log('用户点击确定');
												uni.navigateBack();
												
													
									        } else if (res.cancel) {
									            console.log('用户点击取消');
									        }
									    }
								})
								this.cstatus=true;
								uni.hideLoading();
							} else {
								this.cstatus=true;
								uni.hideLoading();
								uni.showModal({
									title: "操作失败",
									content: "操作失败！",
									showCancel: false,
									confirmText: "确定"
								})
							}
						}
					});
				
				
				
				
			}
			
		}
	}
</script>

<style>
.login{position: absolute;top:0;left:0;right:0;bottom:0;background: #fff;padding-top: 20upx;}
.inputStyle{height: 96rpx;width: 660rpx;border:1rpx solid #dadada;font-size: 28rpx;
display: block;margin:0 auto;margin-bottom:40rpx;border-radius: 2px;text-indent: 15rpx;}
.inputStyle:focus{border:1rpx solid  rgb(211, 61, 62);}
.logo{width: 90%;margin:30rpx auto 60rpx;display: block;}
.buttonStyle{width: 660rpx;margin:0 auto;border-radius: 2px;background: rgb(211, 61, 62);
color: #fff;font-size: 28rpx;height: 90rpx;line-height: 90rpx;border:none;}
.forget{display: flex;justify-content: space-between;width: 660rpx;
margin:0 auto 100rpx;font-size: 28rpx;}
.forget text{color: rgb(211, 61, 62);}
.forget label {display: flex;align-items: center;}
.forget label image{width: 32rpx;height:32rpx;margin-right: 10rpx;}
</style>
